/*
 * Copyright (c) 2018 - 2019. www.vtuzx.com Inc. All Rights Reserved
 */

package com.vtuzx.kingdee.xqc_core.dao;

import com.vtuzx.core.db.mongo.impl.VtuzxDaoImpl;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_core.bean.kingdee.KingdeeAccount;
import com.vtuzx.kingdee.xqc_core.constant.ConfigType;
import org.bson.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Component;

/**
 * 店铺TokenDAO
 */
@Component
public class StoreTokenDao extends VtuzxDaoImpl {
    /** 店铺Token集合名 */
    public static String NAME = "m_storeToken";
    /**
     * 构造器
     */
    public StoreTokenDao() {
        super(NAME);
    }

    /**
     * 更新金蝶账号信息
     *
     * @param document 金蝶账号
     */
    public void updateKingdee(Document document) {
        updateOne(Criteria.where("type").is(ConfigType.Kingdee.toString()), document);
    }

    /**
     * 获取金蝶账号信息
     *
     * @return 返回聚水潭账号
     */
    public KingdeeAccount getKingdeeAccount() {
        Document doc = getKingdeeConfig();
        return new KingdeeAccount(
                VtuzxUtil.getString(doc, "url"),
                VtuzxUtil.getString(doc, "dataCenter"),
                VtuzxUtil.getString(doc, "account"),
                VtuzxUtil.getString(doc, "password"),
                VtuzxUtil.getInt(doc, "lang"));
    }

    /**
     * 获取金蝶账号信息
     *
     * @return 返回聚水潭账号
     */
    public Document getKingdeeConfig() {
        return findOne(Criteria.where("type").is(ConfigType.Kingdee.toString()));
    }

    /**
     * 获取金蝶账号信息
     *
     * @return 返回聚水潭账号
     */
    public KingdeeAccount getKingdeeAccountYX() {
        Document doc = getKingdeeConfigYX();
        return new KingdeeAccount(
                VtuzxUtil.getString(doc, "url"),
                VtuzxUtil.getString(doc, "dataCenter"),
                VtuzxUtil.getString(doc, "account"),
                VtuzxUtil.getString(doc, "password"),
                VtuzxUtil.getInt(doc, "lang"));
    }

    /**
     * 获取金蝶账号信息
     *
     * @return 返回聚水潭账号
     */
    public Document getKingdeeConfigYX() {
        return findOne(Criteria.where("type").is("kingdee3"));
    }


    public Document getKingdeeConfigYeXiang() {
        return findOne(Criteria.where("type").is("kingdee3"));
    }

    public KingdeeAccount getKingdeeAccountYeXiang() {
        Document doc = getKingdeeConfigYeXiang();
        return new KingdeeAccount(
                VtuzxUtil.getString(doc, "url"),
                VtuzxUtil.getString(doc, "dataCenter"),
                VtuzxUtil.getString(doc, "account"),
                VtuzxUtil.getString(doc, "password"),
                VtuzxUtil.getInt(doc, "lang"));
    }
}
